package com.exam.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.exam.entity.ApiResult;
import com.exam.entity.Teacher;
import com.exam.serviceimpl.TeacherServiceImpl;
import com.exam.util.ApiResultHandler;
import com.exam.vo.AnswerVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
public class TeacherController {

    private TeacherServiceImpl teacherService;
    @Autowired
    public TeacherController(TeacherServiceImpl teacherService){
        this.teacherService = teacherService;
    }

    @GetMapping("/teachers/{page}/{size}")
    public ApiResult findAll(@PathVariable Integer page, @PathVariable Integer size){
        Page<Teacher> teacherPage = new Page<>(page,size);
        IPage<Teacher> teacherIPage = teacherService.findAll(teacherPage);

        return ApiResultHandler.buildApiResult(200,"查询所有教师",teacherIPage);
    }

    @GetMapping("/teacher/{teacherId}")
    public ApiResult findById(@PathVariable("teacherId") Integer teacherId){
        return ApiResultHandler.success(teacherService.findById(teacherId));
    }

    @DeleteMapping("/teacher/{teacherId}")
    public ApiResult deleteById(@PathVariable("teacherId") Integer teacherId){
        return ApiResultHandler.success(teacherService.deleteById(teacherId));
    }

    @PutMapping("/teacher")
    public ApiResult update(@RequestBody Teacher teacher){
        return ApiResultHandler.success(teacherService.update(teacher));
    }
//    职称
    @GetMapping("/zcs")
    public ApiResult findZc(){
        List<String> ZC = null ;
        ZC = teacherService.findZC();
        System.out.printf("zcccc"+ZC);
        return ApiResultHandler.buildApiResult(200,"查询所有职称",ZC);
    }
//    专业
    @GetMapping("/zy")
    public ApiResult findZy(){
        List<String> Zy = null ;
        Zy = teacherService.findZy();
        System.out.printf("zcccc"+Zy);
        return ApiResultHandler.buildApiResult(200,"查询所有专业",Zy);
    }
    //    专业
    @GetMapping("/zy/{college}")
    public ApiResult findZy(@PathVariable("college") String college){
        List<String> Zy = null ;
        Zy = teacherService.findZy(college);
        System.out.printf("zcccc"+Zy);
        return ApiResultHandler.buildApiResult(200,"查询所有专业",Zy);
    }
//    学院
    @GetMapping("/xys")
    public ApiResult findXy(){
        List<String> Xy = null ;
        Xy = teacherService.findXy();
        System.out.printf("zcccc"+Xy);
        return ApiResultHandler.buildApiResult(200,"查询所有学院",Xy);
    }
    @PostMapping("/teacher")
    public ApiResult add(@RequestBody Teacher teacher){
        return ApiResultHandler.success(teacherService.add(teacher));
    }
}
